package com.example.dialog;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private AlertDialog.Builder alertDialog;
    private AlertDialog.Builder builder;

    private Button btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn=findViewById(R.id.Sum);
        btn.setOnClickListener(this);

    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.Sum:
                Sum();

                break;
            default:
                break;
        }
    }

    private void  Sum(){
        alertDialog = new AlertDialog.Builder(this);
        View view= View.inflate(MainActivity.this,R.layout.dialog_1,null);
        final EditText num1=view.findViewById(R.id.editText3);
        final EditText num2=view.findViewById(R.id.editText4);
        final Button btnSum=view.findViewById(R.id.btnGo);
        alertDialog.setView(view);
        alertDialog.create().show();
        if(num1.length()!=0){

        }
        btnSum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int Num1= Integer.parseInt(num1.getText().toString());
                int Num2= Integer.parseInt(num2.getText().toString());
                int sum=Num1+Num2;
                String str1= Integer.toString(sum);
                switch (v.getId()){
                    case R.id.btnGo:

                        sum(str1);
                        alertDialog.create().dismiss();
                        break;
                    default:
                        break;
                }
            }
        });

    }
    private void  sum(String str){
        builder=new AlertDialog.Builder(this);
        View view2=View.inflate(MainActivity.this,R.layout.dialog_2,null);
        final EditText sum1=view2.findViewById(R.id.tv_Sum);
        builder.setView(view2);
        builder.create().show();
        sum1.setText(str);

    }
}